<template>
	<view class="apply">
		<nav-bars bgColor="#fff"></nav-bars>
		<view class="applyBox">
			<view class="topText">
				<text>申请贷款</text>
				<view>最长贷款期限8年</view>
			</view>
			<view class="infoBox">
				<!-- <view class="item">
					<text>订单号</text>
					<view class="select" @click="openSelect(1)">
						请选择订单<view class="iconfont icon-more"></view>
					</view>
				</view> -->
				<view class="item">
					<text>贷款金额</text>
					<input type="number" value="" v-model="loan_amount" placeholder-class="inputPlace" placeholder="请输入贷款金额" />
				</view>
				<view class="item">
					<text>还款期限</text>
					<view class="select" @click="openSelect">
						{{repay_term}}月<view class="iconfont icon-more"></view>
					</view>
				</view>
			</view>
			<u-select v-model="show" :default-value="defaultValue" :list="list" @confirm="confirmSelect"></u-select>
			<view class="btn">
				<button type="default" @click="toSubmit">确定</button>
			</view>
		</view>
	</view>
</template>

<script>
	import service_decLoan from '@/service/decLoan.js'
	export default{
		data(){
			return{
				show:false,
				list:[{
					label:'3月',
					value:3
				},{
					label:'6月',
					value:6
				},{
					label:'9月',
					value:9
				},{
					label:'12月',
					value:12
				},{
					label:'24月',
					value:24
				},{
					label:'36月',
					value:36
				},{
					label:'48月',
					value:48
				},{
					label:'60月',
					value:60
				},{
					label:'72月',
					value:72
				},{
					label:'84月',
					value:84
				},{
					label:'96月',
					value:96
				}],
				loan_amount:'', //贷款金额
				repay_term:12, //月份
				order_no:'', //订单号
				defaultValue:[3],
				order_type:0, //订单类型(1普通商品,2产品包,3设计师,4施工队)
			}
		},
		onLoad(options) {
			this.$utils.getUrl()
		},
		methods:{
			// 选择
			openSelect(){
				this.show = true
			},
			
			// 选择确定
			confirmSelect(e){
				this.repay_term = e[0].value
			},
			
			// 确定按钮
			toSubmit(){
				if(this.loan_amount==''){
					uni.showToast({title:'请输入贷款金额',icon:'none'})
					return
				}
				if(this.loan_amount>500000){
					uni.showToast({
						title:'贷款金额最高为50万',
						icon:'none'
					})
					return
				}
				let params = {
					loan_amount:this.loan_amount,
					repay_term:this.repay_term,
					order_no:this.order_no,
					order_type:this.order_type
				}
				console.log(params,'申请数据')
				service_decLoan.applyLoan(params).then(res=>{
					console.log(res,'申请结果')
					if(res.code==1){
						uni.navigateTo({
							url:'../success/success'
						})
					}else{
						uni.showToast({
							title:res.msg,
							icon:'none'
						})
					}
				})
				
			}
		}
	}
</script>

<style lang="less">
	page{height: 100%;}
	.apply{
		height: 100%;
		background-color: #fff;
		padding: 50rpx;
		.applyBox{
			.topText{
				padding: 0 20rpx;
				font: bold 34rpx/50rpx PingFang SC;
				color: #C3AB7C;
				text{
					font: 500 60rpx/90rpx PingFang SC;
					color: #333;
				}
			}
			.infoBox{
				margin-top: 100rpx;
				.item{
					display: flex;
					align-items: center;
					justify-content: space-between;
					border-bottom: 2rpx solid #F1F1F1;
					padding: 40rpx 0 30rpx 0 ;
					font: 500 30rpx/30rpx PingFang SC;
					color: #333;
					text{
						
					}
					input{
						width: 50%;
						text-align: right;
						font: 500 30rpx/30rpx PingFang SC;
						color: #999;
					}
					.select{
						display: flex;
						align-items: center;
						color: #999;
					}
					.inputPlace{
						font: 500 30rpx/30rpx PingFang SC;
						color: #999;
					}
					.iconfont{
						color: #999;
						font-size: 30rpx;
					}
				}
			}
			// 按钮
			.btn{
				width: 100%;
				margin-top: 40rpx;
				button{
					width: 650rpx;
					height: 90rpx;
					margin: 20rpx auto;
					background-color: #C3AB7C;
					border-radius: 10rpx;
					font: 500 34rpx/90rpx PingFang SC;
					color: #fff;
				}
			}
		}
	}
</style>
